import {
  Body,
  Controller,
  Delete,
  Get,
  Header,
  Param,
  Post,
  Put,
  Query,
  Redirect,
} from '@nestjs/common';
import { CatService } from './cats.service';

export class CreateCatDto {
  id: number;
  name: string;
}

export class UpdateCatDto {
  name: string;
}

@Controller('cats')
export class CatsController {
  constructor(private readonly catService: CatService) {}

  @Post()
  async create(@Body() createCatDto: CreateCatDto) {
    return this.catService.create(createCatDto);
  }

  @Delete(':id')
  async remove(@Param('id') id) {
    await this.catService.remove(id);
    // return `This action removes a #${id} cat`;
  }

  @Put(':id')
  async update(@Param('id') id, @Body() updateCatDto: UpdateCatDto) {
    await this.catService.update(id, updateCatDto);
  }

  @Get(':id')
  async findOne(@Param('id') id) {
    await this.catService.findOne(id);
  }

  @Get()
  @Redirect('https://nestjs.com', 301)
  async findAll(@Query('version') version) {
    if (version) {
      return { url: 'https://docs.nestjs.com/v5/' };
    }
    // console.log(query);
    // await this.catService.findAll();
  }
}
